/**
 * @author klv
 */
var QS_ISearchFilter={
	setDefault:function(){
		
	},
	reset:function(){
		
	}
};

var QS_SliderFilter=function(cellDOM,config,callback){
	this.config = {
		width: 150,
		showTip: true,
		showInput: true,
		tipMoveable: false
	};
	$.extend(this.config,config);
	this.slider = new slider(cellDOM,this.config,callback);
};
QS_SliderFilter.prototype=$.extend({},QS_ISearchFilter,{
	setDefault:function(selected){
		this.slider.setSliderBarValue(selected,true);
	},
	reset:function(){
		this.slider.reset();
	}
});

var QS_MStyleBoxFilter=function(cellDOM,config,callback){
	this.config = {
		width: 80,
		isMainRange: true,
		clickable: true,
		showHeader: true
	};
	$.extend(this.config,config);
	this.msb=new Util.styleBox(cellDOM, this.config,callback);
};
QS_MStyleBoxFilter.prototype=$.extend({},QS_ISearchFilter,{
    setDefault:function(selected){
        this.msb.bindData(selected);
    },
    reset:function(){
        this.msb.reset();
    }
});

var QS_RadioButtonFilter=function(cellDOM,data,config,callback){
	this.config={
		type: 'checkbox',
        vertical: false,
        needTitle:true
	};
	$.extend(this.config,config);
	this.buttonList=new Util.ButtonGroup(cellDOM,data,callback,this.config);
};
QS_RadioButtonFilter.prototype=$.extend({},QS_ISearchFilter,{
    setDefault:function(selected){
        for (var b in this.buttonList.btns) {
            if($.inArray(b,selected)!=-1){
                this.buttonList.btns[b].select();
            }else{
                this.buttonList.btns[b].inverse();
            }
        }
    },
    reset:function(){
        for (var b in this.buttonList.btns) {
            this.buttonList.btns[b].inverse();
        }
    }
});

var QS_MStarFilter=function(cellDOM,config,callback){
	this.config={};
	$.extend(this.config,config);
	this.star=new Util.star(cellDOM, this.config,callback);
};
QS_MStarFilter.prototype=$.extend({},QS_ISearchFilter,{
	setDefault:function(selected){
        this.star.setScore(selected[0]||0);
    },
    reset:function(){
        this.star.reset();
    }
});

var QS_InputFilter=function(cellDOM,config,callback){
    this.config={
		defaultValue:[]
	};
	$.extend(this.config,config);
	this.callback=callback;
	this.el=$('<input type="text" class="'+(!this.config.className?'qs-ui-ipt':this.config.className)+ '" value="">').appendTo(cellDOM);
	var self=this;
	this.el.bind("keyup",function(e){
		self.callback.onKeyup(this.value);
	});
	this.setDefault(this.config.defaultValue);
};
QS_InputFilter.prototype=$.extend({},QS_ISearchFilter,{
    setDefault:function(selected){
		if (selected.length > 0) {
			this.el.val(selected[0] || "");
		}else{
			this.reset();
		}
    },
    reset:function(){
        this.el.val("");
    }
});

var QS_DropDownFilter=function(cellDOM,config,callback){
    this.config={
        defaultValue:[]
    };
    $.extend(this.config,config);
	this.callback=callback;
    this.el=$('<a class="'+(!this.config.className?'qs-ui-btn':this.config.className)+'"></a>').appendTo(cellDOM);
    var self=this;
    this.el.bind("mouseover",function(e){
        self.callback.onMouseOver(e);
    }).bind("mouseout",function(e){
		self.callback.onMouseOut(e);
	});
	this.setDefault(this.config.defaultValue);
};
QS_DropDownFilter.prototype=$.extend({},QS_ISearchFilter,{
    setDefault:function(selected){
		var ln=selected.length;
        if (ln > 0) {
            this.el[0].innerHTML = 'Selected ' + ln + ' item' + (ln > 1 ? 's' : '') + ' [Edit...]';
        }
        else {
            this.el[0].innerHTML = 'Select...';
        }
    },
    reset:function(){
        this.el[0].innerHTML = 'Select...';
    },
	getDom:function(){
		return this.el;
	}
});

var QS_CheckBoxFilter=function(cellDOM,config,callback){
    this.config={
        defaultValue:[]
    };
    $.extend(this.config,config);
    this.callback=callback;
    this.el=$('<a class="'+(!this.config.className?'qs-ui-btn':this.config.className)+'"></a>').appendTo(cellDOM);
    var self=this;
    this.el.bind("click",function(e){
        self.callback.onClick(e);
    });
	this.setDefault(this.config.defaultValue);
};
QS_CheckBoxFilter.prototype=$.extend({},QS_ISearchFilter,{
    setDefault:function(selected){
		var ln=selected.length;
        if (ln > 0) {
            this.el[0].innerHTML = 'Selected ' + ln + ' item' + (ln > 1 ? 's' : '') + ' [Edit...]';
        }
        else {
            this.el[0].innerHTML = 'Select';
        }
    },
    reset:function(){
        this.el[0].innerHTML = 'Select';
    },
	getDom:function(){
        return this.el;
    }
});




